package com.cbg.es.service.impl;

import com.cbg.es.dto.EsTableListDTO;
import com.cbg.es.entity.EsTableCategory;
import com.cbg.es.repository.IEsTableCategoryRepository;
import com.cbg.es.service.IEsTableCategoryService;
import com.shuyuwl.core.enums.StatusEnum;
import com.shuyuwl.core.exception.SymServiceException;
import com.shuyuwl.core.service.impl.DaoServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 全景通查分类下展示表 serviceImpl
 *
 * @author wangjuzheng
 * @since 2019-10-16
 */
@Service
@Transactional(rollbackFor = SymServiceException.class)
public class EsTableCategoryServiceImpl extends DaoServiceImpl<EsTableCategory, Long, IEsTableCategoryRepository> implements IEsTableCategoryService {

    @Resource
    private IEsTableCategoryRepository esTableCategoryRepository;

    @Override
    public List<EsTableCategory> findByCategoryId(Long categoryId) {
        return esTableCategoryRepository.findByCategoryIdAndStatusLessThanOrderBySortAsc(categoryId, StatusEnum.DELETE.getCode());
    }

    @Override
    public List<EsTableCategory> getAllEsTableCategory(List<Long> tableCategoryIds) {
        return esTableCategoryRepository.getAllEsTableCategory(tableCategoryIds, StatusEnum.DELETE.getCode(), StatusEnum.OK.getCode());
    }

    @Override
    public void deleteByCategoryId(Long categoryId) {
        esTableCategoryRepository.deleteByCategoryId(categoryId, StatusEnum.DELETE.getCode());
    }
    @Override
    public EsTableCategory findById(Long tableCategoryId) {
        return esTableCategoryRepository.findByIdAndStatusLessThanOrderBySortAsc(tableCategoryId, StatusEnum.DELETE.getCode());
    }

    @Override
    public Integer getMaxSort(Long categoryId) {
        return esTableCategoryRepository.getMaxSort(categoryId, StatusEnum.DELETE.getCode());
    }

    @Override
    public List<EsTableListDTO> selectedCategory(Long categoryId) {
        return esTableCategoryRepository.selectedCategory(categoryId, StatusEnum.DELETE.getCode(), StatusEnum.OK.getCode());
    }

    @Override
    public void deleteByCategoryIdAndTableCategoryIdNeqIn(Long categoryId, List<Long> ids) {
        esTableCategoryRepository.deleteByCategoryIdAndTableCategoryIdNeqIn(categoryId, ids, StatusEnum.DELETE.getCode());
    }
}
